<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 
    JSP Name : rt_100_04.jsp
    Description : 커뮤니티 상세
    author EUNGA
    since 2012. 7. 25.
    version 1.0
    Modification Information
       since          author              description
    ===========    =============    ===========================
    2012. 7. 25.     EUNGA     최초 생성
--%>
<%@ include file="/WEB-INF/jsp/co/us/include/declare.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>현대자동차 CSR &#124; 공모사업 커뮤니티</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<%@ include file="/WEB-INF/jsp/co/us/include/header.jspf" %>
<script type="text/javaScript" language="javascript">
$(document).ready(function() {    
    /* form validation check */
    onloadCharCheck();
    
    selectCmtList();
    
    /* List Page 이동 */
    $("#listButn").bind("click", moveListPage);
    /* Form Submit */
    $("#mdfyButn").bind("click", mdfySubm);
    /* Form Submit */
    $("#rpReButn").bind("click", rpReButn);
    
    $("#delButn").bind("click", delSubmit);    // 삭제
});

/*
 * 리스트페이지 이동
 */
function moveListPage() {
    var listUrl = "/rt_100_03.do";
    if("Image" == "${rqInfo.listType}"){
        listUrl = "/rt_100_02.do";
    }
    $("#mainForm").attr('action',listUrl).submit();
}
  
/*
 * 수정 페이지로 이동
 */
function mdfySubm() {
    $("#mainForm").attr('action','/rt_100_07.do').submit();
}

/*
 * 게시물 삭제
 */
function delSubmit() {
    if (confirm("삭제하시겠습니까?")) {
        $("#mainForm").attr('target','comIframe');
        $("#mainForm").attr('action','/rt_100_27.do').submit();   
    } else {
        return false;
    }
}

/*
 * 덧글 입력
 */
function rpReButn(glfdIdx) {
    var submitUrl = "/rt_100_09.do";
    var sbcTxt = "";
    var param = "";
    
    if(glfdIdx == 0){ // 덧글인 경우
        sbcTxt = encodeURIComponent(encodeURIComponent($("#cmtSbc").val()));
        if(sbcTxt == "" || sbcTxt == null){
            alert("내용을 입력 하세요.");
            return;
        }
        param = "sbc=" + sbcTxt + "&blbIdx=" + $("#blbIdx").val();
        
        $("#glfdIdx").val("");
        $("#sbc").val($("#cmtSbc").val());
        $("#dept").val(0);
    }else{ // 답글인경우
        sbcTxt = encodeURIComponent(encodeURIComponent($("#cmtSbc_" + glfdIdx).val()));
        if(sbcTxt == "" || sbcTxt == null){
            alert("내용을 입력 하세요.");
            return;
        }
        param = "sbc=" + sbcTxt + "&blbIdx=" + $("#blbIdx").val() + "&glfdIdx=" + glfdIdx + "&dept=1";
        
        $("#sbc").val($("#cmtSbc_" + glfdIdx).val());
        $("#glfdIdx").val(glfdIdx);
        $("#dept").val(1);
    }
    
    $("#replyForm").attr('target','relplyFrame');
    $("#replyForm").attr('action', submitUrl);
    $("#replyForm").submit();
    
    //ajaxSubmit(submitUrl,param,selectCmtList) ;
}

/* textarea form */
function cmtForm(glfdIdx){
    $("#cmtInput_" + glfdIdx).toggle();
    $("#CmtText_" + glfdIdx).text($("#CmtText_" + glfdIdx).text() == "답글달기" ? "답글취소" : "답글달기");
}

/* textarea form */
function cmtDel(cmtIdx){
    var submitUrl = "/rt_100_11.do";
    var param = "cmtIdx=" + cmtIdx;
    if(confirm("삭제 하시겟습니까?")){
        ajaxSubmit(submitUrl,param,selectCmtList) ;
    }
}

/*
 * 덧글 조회
 */
function selectCmtList() {
    var submitUrl = "/rt_100_10.do";
    var param = "blbIdx=" +$("#blbIdx").val();
    ajaxSubmit(submitUrl,param,rpList) ;
}

/*
 * 덧글 리스트 작성
 */
function rpList(jsonData) {
    
    var html = "";
    var totalCnt = "0";
    var evalData = eval(jsonData);
    if (jsonData != null) {
        totalCnt = evalData.jsonArray.length;
    }
    
    var htmlTxt = "<div class='commentFrm'><textarea rows='2' cols='85' id='cmtSbc' name='cmtSbc'></textarea>";
        htmlTxt = htmlTxt +  "<input id='rpReButn' name='rpReButn' onClick='rpReButn(0)' type='image' src='/img/mng/btn/btn_comment.gif' alt='댓글작성' title='댓글작성' /></div>";
        htmlTxt = htmlTxt +  "<div class='commentArea'>";
        htmlTxt = htmlTxt +  "<p class='commentNo'>댓글 "+ totalCnt +"개</p>";
        if (jsonData != null && (evalData.jsonArray.length > 0 || evalData.jsonArray != null)) {
            for (var i = 0; i < evalData.jsonArray.length; i++) {
                if(evalData.jsonArray[i].dept == 0 ){
                    htmlTxt = htmlTxt + "<div class='commentView'>";
                }else{
                    htmlTxt = htmlTxt + "<div class='commentView reply'>";
                }
                htmlTxt = htmlTxt + "<p class='writerInfo'><strong>" + evalData.jsonArray[i].pprrNm + "</strong><span>" + evalData.jsonArray[i].rgstDt + "</span></p>";
                htmlTxt = htmlTxt + "<p class='comment'>" + evalData.jsonArray[i].sbc + "</p>";
                if(evalData.jsonArray[i].dept == 0 ){
                    htmlTxt = htmlTxt + "<div class='btnCmt'><button id='CmtText_" + evalData.jsonArray[i].glfdIdx + "' type='button' onClick='cmtForm(" + evalData.jsonArray[i].glfdIdx + ")'>답글달기</button>";
                    if('${userIdx }' == evalData.jsonArray[i].userIdx){
                    htmlTxt = htmlTxt + "&#124;<input onClick='cmtDel(" + evalData.jsonArray[i].cmtIdx + ")' type='submit' value='삭제' title='삭제' />";
                    }
                    htmlTxt = htmlTxt + "</div>";
                    htmlTxt = htmlTxt + "<div id='cmtInput_" + evalData.jsonArray[i].glfdIdx + "' class='commentFrm'>";
                    htmlTxt = htmlTxt + "<textarea id='cmtSbc_" + evalData.jsonArray[i].glfdIdx + "' rows='2' cols='85'></textarea><input type='image' onClick='rpReButn("+evalData.jsonArray[i].glfdIdx+")' src='/img/mng/btn/btn_comment.gif' alt='댓글작성' title='댓글작성' /></div>";
                }else{
                    htmlTxt = htmlTxt + "<div class='btnCmt'>"; 
                    if('${userIdx }' == evalData.jsonArray[i].userIdx){
                        htmlTxt = htmlTxt + "<input type='submit' onClick='cmtDel(" + evalData.jsonArray[i].cmtIdx + ")' value='삭제' title='삭제' />";
                    }
                    htmlTxt = htmlTxt + "</div>";
                }
                
                htmlTxt = htmlTxt + "</div>";
                
            }
        }
        htmlTxt = htmlTxt +  "</div>";
        
    $("#commentDiv").html(htmlTxt);
}
</script>
</head>
<body>
<div id="wrap">
    <!-- top -->
    <%@ include file="/WEB-INF/jsp/co/us/include/top.jsp" %>
    <!-- top -->

    <!-- container -->
    <div id="container">
        <div id="contentsWrap">
            <div id="contentsArea">
                <div class="headingArea">
                    <div class="location">
                        <a href="/ma_100_01.do">홈</a>
                        <a href="/rt_100_01.do">사회공헌</a>
                        <a href="/rt_100_01.do">공모사업</a>
                        <span>공모사업 커뮤니티</span>
                    </div>
                    <h2>공모사업</h2>
                    <ul class="menuTab">
                        <li><h3><a href="/rt_100_01.do">사업소개</a></h3></li>
                        <li class="atv"><h3><a href="/rt_100_02.do">공모사업 커뮤니티</a></h3></li><!-- current menu : add class "atv" -->
                    	<li><h3><a href="/rt_100_31.do">FAQ</a></h3></li>
					</ul>
                </div>
                <div id="contetns" class="businessCommunity">
                    <form id="mainForm" name="mainForm" method="post">
                    <input type="hidden" id="currentPageNo" name="currentPageNo" value="${rqInfo.currentPageNo }" />
                    <input type="hidden" id="srchScn" name="srchScn" value="${rqInfo.srchScn }" />
                    <input type="hidden" id="srchTxt" name="srchTxt" value="${rqInfo.srchTxt }" />
                    <input type="hidden" id="blbIdx" name="blbIdx" value="${rqInfo.blbIdx }" />
                    <input type="hidden" id="listType" name="listType" value="${rqInfo.listType }" />
                    <table border="1" class="tableData" summary="공모사업 커뮤니티의 기관명, 작성자, 등록일, 조회수, 이메일, 제목, 첨부파일 등이 기재 되어있는 표">
                        <col width="20%" />
                        <col width="30%" />
                        <col width="20%" />
                        <col width="30%" />
                        <tbody>
                            <tr>
                                <td class="subThead">기관명</td>
                                <td>${result.instNm }</td>
                                <td class="subThead depth">작성자</td>
                                <td>${result.pprrNm }</td>
                            </tr>
                            <tr>
                                <td class="subThead">등록일</td>
                                <td class="num">${result.rgstDt }</td>
                                <td class="subThead depth">조회수</td>
                                <td class="num">${result.iqNo }</td>
                            </tr>
                            <tr>
                                <td class="subThead">이메일</td>
                                <td colspan="3">${result.eml }</td>
                            </tr>
                            <tr>
                                <td class="subThead">제목</td>
                                <td colspan="3">${result.titl }</td>
                            </tr>
                            <tr>
                                <td class="subThead">첨부파일</td>
                                <td colspan="3"><a href="#" onclick="getUpFileDownload('0050','${result.blbIdx}');return false;">${result.filNm }</a></td></td>
                            </tr>
                            <tr>
                                <td colspan="4" class="dataView">
                                    <div class="viewArea">
                                    <c:if test="${result.thumnImgNm != null && result.thumnImgPath != null }">
                                        <img src="/upfile/${result.thumnImgPath }/${result.thumnImgNm }" border="0" /><br/><br/>
                                    </c:if>
                                        ${result.sbc}
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    </form>
                    <form id="replyForm" name="replyForm" method="post">
                        <input type="hidden" id="sbc" name="sbc" value="" />
                        <input type="hidden" id="glfdIdx" name="glfdIdx" value="" />
                        <input type="hidden" id="blbIdx" name="blbIdx" value="${result.blbIdx }" />
                        <input type="hidden" id="dept" name="dept" value="" />
                    </form>
                    <div id="commentDiv" name="commentDiv" class="commentWrap">
                    </div>
                    <div class="btnArea down">
                        <span class="flow"><a href="#" id="listButn" name="listButn" ><img src="/img/usr/btn/btn_list.gif" alt="목록" /></a></span>
                        <span class="reverse">
                        <c:if test="${result.mdfyYn == 'Y' }">
                            <input id="mdfyButn" name="mdfyButn" type="image" src="/img/usr/btn/btn_modify.gif" title="수정" alt="수정" />
                            <input id="delButn" name="delButn" title="삭제" type="image" src="/img/usr/btn/btn_delete.gif"  value="삭제"/>
                        </c:if>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /container -->

    <!-- footer -->
    <%@ include file="/WEB-INF/jsp/co/us/include/bottom.jsp" %>
    <!-- /footer -->
    <iframe id="relplyFrame" name="relplyFrame" frameborder="0" height="0" width="0"></iframe>
</div>
</body>
</html>